package com.cx.service.impl;

import com.cx.mapper.GroupMemberMapper;
import com.cx.pojo.GroupMember;
import com.cx.service.GroupMemberService;
import com.cx.vo.GroupMemberVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author: Zhou wei
 * @create: 2020/5/27 22:46
 */
@Service
public class GroupMemberServiceImpl implements GroupMemberService {

    @Autowired
    GroupMemberMapper groupMemberMapper;

    @Override
    public int joinGroup(Integer userId, Integer groupSponsorId) {
        GroupMember groupMember = new GroupMember();
        groupMember.setUserId(userId);
        groupMember.setGroupSponsorId(groupSponsorId);
        groupMember.setCreateTime(new Date());
        groupMember.setUpdateTime(new Date());

        int affectedRows = groupMemberMapper.insertSelective(groupMember);

        return affectedRows;
    }

    @Override
    public List<GroupMemberVO> selectGroupMemberByGroupSponsorId(Integer groupSponsorId) {
        List<GroupMemberVO> groupMemberVOList = groupMemberMapper.selectGroupMemberByGroupSponsorId(groupSponsorId);
        return groupMemberVOList;
    }

    @Override
    public Integer countGroupByGoodId(Integer userId, Integer groupGoodId) {
        Integer count = groupMemberMapper.countGroupByGoodId(userId, groupGoodId);
        return count;
    }
}
